package master.ghrm.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Version;

@Entity
public class Questioneer extends AbstractBaseEntity {
	private static final long serialVersionUID = 1L;

	public static final int LENGTH_NAME = 80;

	@Version
	private Long version;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "questioneer_id")
	private Integer questioneerId;

	@Column(nullable = false, length = LENGTH_NAME)
	private String name;

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "tbl_questioneer_category", joinColumns = { @JoinColumn(name = "questioneer_id", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "eval_category_id", nullable = false, updatable = false) })
	private List<EvalCategory> evalCategories = new ArrayList<EvalCategory>(0);

	// @OneToMany(fetch = FetchType.LAZY, mappedBy = "questioneer")
	// private List<Evaluation> evaluations = new ArrayList<Evaluation>(0);

	/**
	 * Default constructor, persistence use.
	 */
	public Questioneer() {
		evalCategories = new ArrayList<EvalCategory>();
	}

	/**
	 * @param aName name
	 * @param questions list of questions.
	 */
	public Questioneer(String aName, List<EvalCategory> anEvalCategories) {
		this.name = aName;
		this.evalCategories = anEvalCategories;
	}

	/**
	 * @return ID.
	 */
	public Integer getQuestioneerId() {
		return this.questioneerId;
	}

	/**
	 * @param aQuestioneerId ID.
	 */
	public void setQuestioneerId(Integer aQuestioneerId) {
		this.questioneerId = aQuestioneerId;
	}

	/**
	 * @return the version
	 */
	public Long getVersion() {
		return version;
	}

	/**
	 * @param aVersion the version to set
	 */
	public void setVersion(Long aVersion) {
		this.version = aVersion;
	}

	/**
	 * @return name.
	 */
	public String getName() {
		return this.name;
	}

	/**
	 * @param aName name.
	 */
	public void setName(String aName) {
		this.name = aName;
	}

	/**
	 * @return the evalCategories
	 */
	public List<EvalCategory> getEvalCategories() {
		return evalCategories;
	}

	/**
	 * @param evalCategoriesList the evalCategories to set
	 */
	public void setEvalCategories(List<EvalCategory> evalCategoriesList) {
		this.evalCategories = evalCategoriesList;
	}

	/**
	 * @param category category to add.
	 */
	public void addCategory(EvalCategory category) {
		if (category != null && !evalCategories.contains(category)) {
			this.evalCategories.add(category);
		}
	}

	/**
	 * @param category category to remove.
	 */
	public void removeCategory(EvalCategory category) {
		this.evalCategories.remove(category);
	}

	// public List<Evaluation> getEvaluations() {
	// return evaluations;
	// }
	//
	// public void setEvaluations(List<Evaluation> evaluationsList) {
	// this.evaluations = evaluationsList;
	// }
	//
	// public Boolean isLocked() {
	// Boolean isLocked = Boolean.FALSE;
	//
	// if (CollectionUtils.isNotEmpty(evaluations)) {
	// for (Evaluation evaluation : evaluations) {
	// isLocked = evaluation.getPublished();
	//
	// if (isLocked) {
	// break;
	// }
	// }
	// }
	//
	// return isLocked;
	// }

	/**
	 * @see com.levi9.hrm.model.base.AbstractBaseEntity#getExcludedAttributes()
	 */
	@Override
	protected String[] getExcludedAttributes() {
		return new String[] { "evalCategories" };
	}

}
